﻿using System.Linq.Expressions;
using System.Reflection;

namespace XEnamel.Python
{
	public static class PythonExtensions
	{
		public static BlockExpression GetBlock(this IronPython.Compiler.Ast.Statement @this)
		{
			return @this.GetType().GetField("_body", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(@this) as BlockExpression;
		}

		public static IronPython.Compiler.Ast.FunctionDefinition GetDefinition(this IronPython.Runtime.PythonFunction @this)
		{
			return @this
				.func_code
				.GetType()
				.GetProperty("PythonCode", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(@this.func_code, null) as IronPython.Compiler.Ast.FunctionDefinition;
		}
	}
}